package com.znufe.exam.controller.vote;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.znufe.exam.domain.vote.VoteConfigInfo;
import com.znufe.exam.service.VoteConfigInfoService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;

import io.swagger.annotations.ApiOperation;

import com.znufe.exam.base.RestResponse;
import com.znufe.exam.base.SystemCode;

/**   
 * 
 * @Description:  答题器基站信息表接口层
 * @Author:       bot   
 * @CreateDate:   VoteConfigInfo
 * @Version:      V1.0
 *    
 */
@Api(tags = "答题器基站信息表",value="答题器基站信息表" )
@RestController
@RequestMapping("/api/vote")
public class VoteConfigInfoController {

	Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	public VoteConfigInfoService voteConfigInfoServiceImpl;
	
	/**
	 * @explain 查询答题器基站信息表对象  <swagger GET请求>
	 * @param   id
	 * @return  voteConfigInfo
	 * @author  bot
	 * @time    VoteConfigInfo
	 */
	@GetMapping("/getVoteConfigInfoById/{id}")
	@ApiOperation(value = "获取答题器基站信息表信息", notes = "获取答题器基站信息表信息[voteConfigInfo]，作者：bot")
	@ApiImplicitParam(paramType="path", name = "id", value = "答题器基站信息表id", required = true, dataType = "Integer")
	public RestResponse<VoteConfigInfo> getVoteConfigInfoById(@PathVariable("id")Integer id){

		try {
			VoteConfigInfo voteConfigInfo=voteConfigInfoServiceImpl.selectByPrimaryKey(id);
			if (voteConfigInfo!=null) {
				return RestResponse.ok(voteConfigInfo);
			} else {
				logger.error("查询答题器基站信息表执行失败："+voteConfigInfo.toString());
				return RestResponse.fail(SystemCode.NoDataExist.getCode(),SystemCode.NoDataExist.getMessage());
			}
		} catch (Exception e) {
			logger.error("查询答题器基站信息表执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}


	/**
	 * @explain 查询最后一条答题器基站信息  <swagger GET请求>
	 * @return  voteConfigInfo
	 * @author  bot
	 * @time    VoteConfigInfo
	 */
	@GetMapping("/getLastVoteConfigInfo")
	@ApiOperation(value = "查询答题器基站连接状态服务", notes = "查询答题器基站连接状态服务 response中voteBaseStatus为1表示已连接成功，为0表示连接失败")
	public RestResponse<VoteConfigInfo> getLastVoteConfigInfo(){

		try {
			//查询最近两个小时内的答题器基站连接信息
			VoteConfigInfo voteConfigInfo=voteConfigInfoServiceImpl.selectLastVoteConfigInfo();

			if (voteConfigInfo!=null) {
				logger.info("查询答题器基站信息表执行成功："+voteConfigInfo.toString());
				return RestResponse.ok(voteConfigInfo);
			} else {
				logger.info("查询答题器基站信息表执行失败："+voteConfigInfo.toString());
				return RestResponse.fail(SystemCode.NoDataExist.getCode(),SystemCode.NoDataExist.getMessage());
			}
		} catch (Exception e) {
			logger.error("查询答题器基站信息表执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}
	
	/**
	 * @explain 添加答题器基站信息表对象
	 * @param   voteConfigInfo
	 * @return  int
	 * @author  bot
	 * @time    VoteConfigInfo
	 */
	@PostMapping("/insertSelective")
	@ApiOperation(value = "添加答题器基站信息表", notes = "添加答题器基站信息表[voteConfigInfo],作者：bot")
	public RestResponse<Integer> insertSelective(@RequestBody VoteConfigInfo voteConfigInfo){
		try {
			int rg=voteConfigInfoServiceImpl.insertSelective(voteConfigInfo);
			if (rg>0) {
				return RestResponse.ok(rg);
			} else {
				logger.error("添加答题器基站信息表执行失败："+voteConfigInfo.toString());
				return RestResponse.fail(SystemCode.InsertDataFail.getCode(),SystemCode.InsertDataFail.getMessage());
			}
		} catch (Exception e) {
			logger.error("添加答题器基站信息表执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}
	
	/**
	 * @explain 删除答题器基站信息表对象
	 * @param   id
	 * @return  int
	 * @author  bot
	 * @time    VoteConfigInfo
	 */
	@PostMapping("/deleteByPrimaryKey")
	@ApiOperation(value = "删除答题器基站信息表", notes = "删除答题器基站信息表,作者：bot")
	@ApiImplicitParam(paramType="query", name = "id", value = "答题器基站信息表id", required = true, dataType = "Integer")
	public RestResponse<Integer> deleteByPrimaryKey(Integer id){
		try {
			int reg=voteConfigInfoServiceImpl.deleteByPrimaryKey(id);
			if (reg>0) {
				return RestResponse.ok(reg);
			} else {
				logger.error("删除答题器基站信息表失败ID："+id);
				return RestResponse.fail(SystemCode.DeleteDataFail.getCode(),SystemCode.DeleteDataFail.getMessage());
			}
		} catch (Exception e) {
			logger.error("删除答题器基站信息表执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}
	
	/**
	 * @explain 修改答题器基站信息表对象
	 * @param   voteConfigInfo
	 * @return  voteConfigInfo
	 * @author  bot
	 * @time    VoteConfigInfo
	 */
	@ApiOperation(value = "修改答题器基站信息表", notes = "修改答题器基站信息表[voteConfigInfo],作者：bot")
	@PostMapping("/updateByPrimaryKeySelective")
	public RestResponse<Integer> updateByPrimaryKeySelective(VoteConfigInfo voteConfigInfo){
		try {
			int reg = voteConfigInfoServiceImpl.updateByPrimaryKeySelective(voteConfigInfo);
			if (reg>0) {
				return RestResponse.ok(reg);
			} else {
				logger.error("修改答题器基站信息表失败ID："+voteConfigInfo.toString());
				return RestResponse.fail(SystemCode.UpdateDataFail.getCode(),SystemCode.UpdateDataFail.getMessage());
			}
		} catch (Exception e) {
			logger.error("修改答题器基站信息表执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}
	
	/**
	 * @explain 获取匹配答题器基站信息表
	 * @param   voteConfigInfo
	 * @return  List<VoteConfigInfo>
	 * @author  bot
	 * @time    VoteConfigInfo
	 */
	@ApiOperation(value = "条件查询答题器基站信息表", notes = "条件查询[voteConfigInfo],作者：bot")
	@PostMapping("/queryVoteConfigInfoList")
	public RestResponse<List<VoteConfigInfo>> queryVoteConfigInfoList(VoteConfigInfo voteConfigInfo){
		try {
			List<VoteConfigInfo> list = voteConfigInfoServiceImpl.queryVoteConfigInfoList(voteConfigInfo);
			return RestResponse.ok(list);
		} catch (Exception e) {
			logger.error("获取答题器基站信息表执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}

}